﻿#include "editwidget.h"
#include "ui_editwidget.h"
#include "iostream"
#pragma execution_character_set("utf-8")

EditWidget::EditWidget(int i,QList<QString> personIf,QWidget *parent) :QWidget(parent),ui(new Ui::EditWidget),
    index(i),personInfo(personIf)
{
    ui->setupUi(this);
    initFun();
    initAttr();
}

void EditWidget::initAttr()
{
    this->setWindowTitle(QString("编辑用户").toUtf8());
    initInfo(personInfo);
    QPalette palette;
    QPixmap pixmap("./images/bg1.jpg");
    palette.setBrush(QPalette::Background, QBrush(pixmap));
    setPalette(palette);

    QPixmap pixmap2("./images/LitterDr.png");
    QIcon icon(pixmap2);
    setWindowIcon(icon);
}

void EditWidget::initFun()
{
    connect(ui->btn_comfirm,&QPushButton::clicked,this,&EditWidget::editPerson);
    connect(ui->btn_cancel,&QPushButton::clicked,this,&EditWidget::cancel);
}


/*
 * @author  : Zeeland
 * @describe: 该函数用于初始化label中显示的信息，数据从tableWidget获取，从mainWindow中传过来
 * @param   : QList<QString> list
 * @return  : null
 */
void EditWidget::initInfo(QList<QString> personInfo)
{
    ui->label_name->setText(personInfo[0]);
    ui->label_number->setText(personInfo[1]);
    ui->label_place->setText(personInfo[2]);
    ui->label_birth->setText(personInfo[3]);
    ui->label_postcode->setText(personInfo[4]);
    ui->label_company->setText(personInfo[5]);
    ui->lineEdit_name->setPlaceholderText(personInfo[0]);
    ui->lineEdit_number->setPlaceholderText(personInfo[1]);
    ui->lineEdit_place->setPlaceholderText(personInfo[2]);
    ui->lineEdit_birth->setPlaceholderText(personInfo[3]);
    ui->lineEdit_postcode->setPlaceholderText(personInfo[4]);
    ui->lineEdit_company->setPlaceholderText(personInfo[5]);

}

/*
 * @author  : Zeeland
 * @describe: 该函数用于修改联系人，输入修改的信息后进行修改
 *            如果在另外一个空间也存在该联系人(判定方式:两个联系人姓名和电话都相等)
 * @param   : QList<QString> list
 * @return  : null
 */
void EditWidget::editPerson()
{

    //判断重名，如果两个位置都有一样的人的名字，将会修改两个空间的人的姓名
    //添加成功
    if(this->index==0)
    {

    }
    else
    {

    }

}

void EditWidget::cancel()
{
    std::cout<<"here"<<std::endl;
    this->close();
}


EditWidget::~EditWidget()
{
    delete ui;
}
